package com.yugao.fintech.draper.core.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Arrays;

@SuppressWarnings("all")
@ToString
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum ErrorCode {

    SUCCESS(200, "成功"),
    SYSTEM_ERROR(500, "失败"),
    RUNTIME_EXCEPTION(1001, "未知错误"),
    NULL_POINT_EXCEPTION(1002, "空指针异常"),
    DB_EXCEPTION(1003, "数据库异常"),
    DUPLICATE_EXCEPTION(1004, "唯一约束异常"),
    METHOD_NOT_SUPPORT_EXCEPTION(1005, "不支持的请求方法"),
    DATA_NOT_EXIST(1006, "数据不存在"),
    PARAMETER_ERROR(1010, "%s参数异常"),
    DATA_IS_USED(1011, "数据被引用，请先删除引用数据"),
    RUNTIME_DATA_EXCEPTION(1050, "%s"),

    MEDIA_NOT_AVALIABLE(1100, "媒体不可用"),
    COMPANY_NOT_AVALIABLE(1101, "企业不可用"),
    ACCOUNT_ERROR(1102, "账号或密码错误"),
    ACCOUNT_DISABLED(1103, "账号被禁用"),
    ACCOUNT_AUTH_ERROR(1104, "账号权限错误"),
    ACCOUNT_NOT_LOGIN(1105, "账号未登录"),
    FILE_NOT_EXIST(1106, "文件不存在");

    private Integer code;

    private String msg;

    public static ErrorCode getValue(String code) {
        return Arrays.stream(values()).filter(v -> v.getCode().equals(code)).findFirst().orElse(SYSTEM_ERROR);
    }
}
